home *** CD-ROM | disk | FTP | other *** search
- #define NAME "testFHUnpack"
- #define REVISION "0"
- #define ENDCODE_NOCTRLC
-
- /* Programmheader
-
- Name: testFHUnpack
- Author: SDI
- Distribution: PD
- Description: easy file to file unpacker using FH's
- Compileropts: -
- Linkeropts: -l xpkmaster amiga
-
- 1.0 02.04.97 : first version
- */
-
- /* NOTE: You may pass option OFFSET, when packed data does not start at
- really file start */
-
- #include <pragma/exec_lib.h>
- #include <pragma/dos_lib.h>
- #include <pragma/xpkmaster_lib.h>
- #include "SDI_defines.h"
-
- #ifdef __MAXON__
- #define __asm
- #define __saveds
- #endif
-
- struct Library *XpkBase = 0;
- ULONG DosVersion = 37;
- struct RDArgs *rda = 0;
- ULONG fhin = 0;
- ULONG fhout = 0;
-
- #define PARAM "FROM/A,TO/A,OFFSET/K/N"
-
- LONG __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
- {
- switch(prog->xp_Type)
- {
- case XPKPROG_START: PutStr("Start: "); break;
- case XPKPROG_MID: PutStr("\rMid : "); break;
- case XPKPROG_END: PutStr("\rEnd : "); break;
- }
-
- if(prog->xp_Type != XPKPROG_END)
- Printf("%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s",
- prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
- prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
- else
- Printf("%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
- prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
- prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
-
- Flush(Output());
- return (LONG) SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
- }
-
- struct Hook chunkhook = { {0}, (ULONG (*)()) chunkfunc};
-
- void main(void)
- {
- ULONG err;
-
- struct {
- STRPTR from;
- STRPTR to;
- ULONG *offset;
- } args = {0, 0, 0};
-
- if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
- !(XpkBase = OpenLibrary(XPKNAME, 4)) ||
- !(fhin = Open(args.from, MODE_OLDFILE)) ||
- !(fhout = Open(args.to, MODE_NEWFILE)) ||
- (args.offset && Seek(fhin, *args.offset, OFFSET_BEGINNING) == -1))
- End(RETURN_FAIL);
-
- if((err = XpkUnpackTags(XPK_InFH, fhin, XPK_OutFH, fhout,
- XPK_ChunkHook, &chunkhook, TAG_DONE)))
- {
- XpkPrintFault(err, "Can't XpkUnpack");
- End(RETURN_FAIL);
- }
-
- End(RETURN_OK);
- }
-
- void end(void)
- {
- if(fhout) Close(fhout);
- if(fhin) Close(fhin);
- if(XpkBase) CloseLibrary(XpkBase);
- if(rda) FreeArgs(rda);
- }
-
-